﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.GamerServices;

namespace FromTheSeaPt1
{
    class GameError : Game
    {
        private SpriteBatch spriteBatch;
        private SpriteFont spriteFont;
        private readonly Exception exception;

        /// <summary>
        /// Graphics manager for the game.
        /// </summary>
        GraphicsDeviceManager graphics;

        public GameError(Exception ex)
        {
            this.exception = ex;
            graphics = new GraphicsDeviceManager(this);
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            //if (GameBase.GamerServices == null)
            //    Components.Add(new GamerServicesComponent(this));

            base.Initialize();

            //if (GameBase.GamerServices != null)
            //    Components.Add(GameBase.GamerServices);
        }

        protected override void LoadContent()
        {
            spriteFont = Content.Load<SpriteFont>("Fonts/debugFont");
            spriteBatch = new SpriteBatch(this.GraphicsDevice);
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                Exit();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {

            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            spriteBatch.DrawString(spriteFont, "**** CRASH LOG ****", new Vector2(100f, 100f), Color.White);
            spriteBatch.DrawString(spriteFont, "Press Back to Exit", new Vector2(100f, 120f), Color.White);
            spriteBatch.DrawString(spriteFont, string.Format("Exception: {0}", exception.Message), new Vector2(100f, 140f), Color.White);
            spriteBatch.DrawString(spriteFont, string.Format("Stack Trace:\n{0}", exception.StackTrace), new Vector2(100f, 160f), Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
